{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "71e08d35-aab7-4613-81b5-11886b131ec4",
   "metadata": {},
   "outputs": [],
   "source": [
    "import cv2\n",
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "39a65c19-a9fa-4dcf-8309-6b6e97a2a340",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 读图片\n",
    "img = cv2.imread('test1.png')\n",
    "\n",
    "cv2.imshow('original', img)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "3a84802f-b2f4-4d5c-a2d3-c0ea2f1ff4e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 灰度化\n",
    "gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)\n",
    "\n",
    "cv2.imshow('gray', gray)\n",
    "cv2.waitKey(0)\n",
    "cv2.destroyAllWindows()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "6d10bd9a-95b2-4086-a13a-f01764aeb1eb",
   "metadata": {},
   "outputs": [
    {
     "ename": "error",
     "evalue": "OpenCV(4.10.0) D:\\a\\opencv-python\\opencv-python\\opencv_contrib\\modules\\xfeatures2d\\src\\surf.cpp:1028: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SURF::create'\n",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31merror\u001b[0m                                     Traceback (most recent call last)",
      "Cell \u001b[1;32mIn[9], line 2\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[38;5;66;03m# 创建SURF对象\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m surf \u001b[38;5;241m=\u001b[39m cv2\u001b[38;5;241m.\u001b[39mxfeatures2d\u001b[38;5;241m.\u001b[39mSURF_create()\n",
      "\u001b[1;31merror\u001b[0m: OpenCV(4.10.0) D:\\a\\opencv-python\\opencv-python\\opencv_contrib\\modules\\xfeatures2d\\src\\surf.cpp:1028: error: (-213:The function/feature is not implemented) This algorithm is patented and is excluded in this configuration; Set OPENCV_ENABLE_NONFREE CMake option and rebuild the library in function 'cv::xfeatures2d::SURF::create'\n"
     ]
    }
   ],
   "source": [
    "# 创建SURF对象\n",
    "surf = cv2.xfeatures2d.SURF_create() # 算法有专利，默认没有"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "55b6290e-cb4b-484b-a78a-408d9dd71d21",
   "metadata": {},
   "outputs": [],
   "source": [
    "kp, des = sift.detect"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.11.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
